<template>
  <div>
    <div>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-card>
      <!-- 搜索框 -->
      <el-input
        placeholder="请输入内容"
        v-model="queryinfo.query"
        clearable
        @clear="getorderList"
        class="input-with-select"
      >
        <el-button
          slot="append"
          icon="el-icon-search"
          @click="onorder"
        ></el-button>
      </el-input>
      <!-- 编辑款 -->
      <el-dialog title="修改地址" :visible.sync="orderVisible" width="50%">
        <el-form
          :model="editruleForm"
          :rules="orderrules"
          ref="orderFormref"
          label-width="100px"
          class="demo-ruleForm"
          @close="addruleclose"
        >
          <el-form-item label="省市区/县" prop="address1">
            <el-cascader
              v-model="editruleForm.address1"
              :options="citydata"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input v-model="editruleForm.address2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="orderVisible = false">取 消</el-button>
          <el-button type="primary" @click="orderaddress">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 详细地址 -->
      <el-dialog title="物流详情" :visible.sync="addressVisible" width="50%">
        <el-timeline :reverse="reverse">
          <el-timeline-item
            v-for="(activity, index) in progressInfo"
            :key="index"
            :timestamp="activity.time"
          >
            {{ activity.context }}
          </el-timeline-item>
        </el-timeline>
        <span slot="footer" class="dialog-footer">
          <el-button @click="addressVisible = false">取 消</el-button>
          <el-button type="primary" @click="addressVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 订单列表 -->
      <el-table
        :data="orderList"
        stripe
        border
        style="width: 100%;font-size:14px"
      >
        <el-table-column type="index" label="#" width="40"></el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格（元）" width="180">
        </el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="180">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="success"
              v-if="scope.row.pay_status === 1"
              plain
              >已付款</el-button
            >
            <el-button size="mini" type="danger" v-else plain>未付款</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="180">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="250">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"
            circle
            @click="orderscope"
          ></el-button>
          <el-button
            size="mini"
            type="success"
            icon="el-icon-location"
            circle
            @click="xiangqing"
          ></el-button>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="queryinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import citydata from './citydata'
export default {
  data() {
    return {
      orderList: [],
      queryinfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      orderVisible: false,
      editruleForm: {
        address1: [],
        address2: ''
      },
      orderrules: {
        address1: [
          { required: true, message: '请选择省市区县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      citydata,
      addressVisible: false,
      //   保存物流信息
      progressInfo: [],
      //   正序排列
      reverse: true
    }
  },
  created() {
    this.getorderList()
  },
  methods: {
    async getorderList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryinfo
      })
      //   console.log(res.data)
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败')
      }
      this.orderList = res.data.goods
      this.total = res.data.total
      //   this.$message.success('获取成功')
    },
    handleSizeChange(newsize) {
      this.queryinfo.pagesize = newsize
      this.getorderList()
    },
    handleCurrentChange(newnum) {
      this.queryinfo.pagenum = newnum
      this.getorderList()
    },
    onorder() {
      alert('你好')
      this.getorderList()
    },
    handleChange() {},
    orderaddress() {},
    addruleclose() {
      this.$refs.orderFormref.resetFields()
    },
    orderscope() {
      this.orderVisible = true
    },
    async xiangqing() {
      //   console.log(id)
      const { data: res } = await this.$http.get('/kuaidi/804909574412544580')
      console.log(res.data)
      if (res.meta.status !== 200) {
        return this.$message.error('获取失败')
      }
      this.progressInfo = res.data
      //   this.$message.success('获取成功')
      this.addressVisible = true
    }
  }
}
</script>

<style>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item.css';

.input-with-select {
  width: 500px !important;
}
.el-cascader {
  width: 100%;
}
</style>
